#!/usr/bin/env/ python
# -*- coding: utf-8 -*-

"""
@author: super
@software: PyCharm
@file: 04_new_pymysql增删改语句操作
@time: 2021/11/10 10:28
"""

import pymysql

if __name__ == '__main__':
    conn = pymysql.connect(host = "localhost", port = 3306, user = "root", password = "root", database = "flask",
                           charset = "utf8")

    cursor = conn.cursor()

    sql = "INSERT INTO `user` VALUES(%s, %s, %s, %s, %s, %s, %s);"

    try:
        row_number = cursor.execute(sql, [16, "longkunyu12345", "123456", 1, 1, "15527347078", "湖北省武汉市"])
        if row_number > 0:
            conn.commit()
            print("新增成功！")
        else:
            print("新增失败!")

    except Exception as e:
        conn.rollback()
        raise e

    finally:
        cursor.close()

        conn.close()